<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="字典名称">
        <el-input v-model="formInline.dicName"></el-input>
      </el-form-item>
      <el-form-item label="字典类型">
        <el-select v-model="formInline.dicType">
          <el-option label="---请选择---" value=""></el-option>
          <el-option label="合同分类" value="Contract_Type"></el-option>
          <el-option label="甲方类型" value="first_party_type"></el-option>
          <el-option label="子公司" value="subsidiary_company"></el-option>
          <el-option
            label="合同允许状态"
            value="contractual_permissible_state"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="show">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="handleAdd">添加</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="handleDel">删除</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="multipleTable" :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="编号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.dic_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字典名称" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.dic_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字典类型" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.dic_type_key }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.dic_describe }}</span>
        </template>
      </el-table-column>
      <el-table-column label="编辑">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row.dic_id)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="show"
      @current-change="show"
      :current-page.sync="psgeIndex"
      :page-sizes="[2, 4, 6, 8]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <el-dialog title="字典添加" :visible.sync="dialogZiDianAddVisible">
      <el-form :model="form">
        <el-form-item label="字典名称">
          <el-input v-model="form.dic_name"></el-input>
        </el-form-item>
        <el-form-item label="字典类型">
          <el-input v-model="form.dic_type_key"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="form.dic_describe"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogZiDianAddVisible = false">取消</el-button>
        <el-button type="primary" @click="AddCun">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="字典编辑" :visible.sync="dialogZiDianUpdateVisible">
      <el-form :model="bform">
        <el-form-item label="ID">
          <span>{{ bform.dic_id }}</span>
        </el-form-item>
        <el-form-item label="字典名称">
          <el-input v-model="bform.dic_name"></el-input>
        </el-form-item>
        <el-form-item label="字典类型">
          <el-input v-model="bform.dic_type_key"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="bform.dic_describe"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogZiDianUpdateVisible = false">取消</el-button>
        <el-button type="primary" @click="UpdateCun">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      psgeIndex: 1,
      pageSize: 2,
      total: 0,
      formInline: {
        dicName: "",
        dicType: "",
      },
      form: {
        dic_key: "",
        dic_name: "",
        dic_type_key: "",
        dic_describe: "",
        creator_name: "wf",
        creator_date: "2022-01-05T02:58:47.117Z",
        modifi_name: "",
        modifi_date: "2022-01-05T02:58:47.117Z",
      },
      bform: {
        dic_id: "",
        dic_key: "",
        dic_name: "",
        dic_type_key: "",
        dic_describe: "",
        creator_name: "wf",
        creator_date: "2022-01-05T02:58:47.117Z",
        modifi_name: "",
        modifi_date: "2022-01-05T02:58:47.117Z",
      },
      dialogZiDianAddVisible: false,
      dialogZiDianUpdateVisible: false,
    };
  },
  created() {
    this.show();
  },
  methods: {
    show() {
      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/Dictionaries/GetDictionariesList?dicName=" +
            this.formInline.dicName +
            "&dicType=" +
            this.formInline.dicType +
            "&pageIndex=" +
            this.psgeIndex +
            "&pageSize=" +
            this.pageSize
        )
        .then((r) => {
          if (r.status == 200) {
            this.tableData = r.data.list;
            this.total = r.data.total;
          }
        });
    },
    handleEdit(id) {
      this.dialogZiDianUpdateVisible = true;

      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/Dictionaries/GetDictionariesFan?id=" +
            id
        )
        .then((r) => {
          if (r.status == 200) {
            this.bform = r.data;
          }
        });
    },
    UpdateCun() {
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/Dictionaries/GetDictionariesUpdate",
          this.bform
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("修改成功");
            this.dialogZiDianUpdateVisible = false;
            this.show();
          }
        });
    },
    handleAdd() {
      this.dialogZiDianAddVisible = true;
    },
    AddCun() {
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/Dictionaries/GetDictionariesAdd",
          this.form
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("添加成功");
            this.dialogZiDianAddVisible = false;
            this.show();
          }
        });
    },
    handleDel() {
      var list = this.$refs["multipleTable"].selection;
      var ids = [];
      if (list.length === 0) {
        this.$message("至少选中一个");
        return false;
      }
      list.forEach((r) => {
        ids.push(r.dic_id);
      });
      if (!confirm("确定删除吗？")) {
        return false;
      }
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/Dictionaries/GetDictionariesDel?ids=" +
            ids
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("删除成功");
            this.show();
          }
        });
    },
  },
};
</script>